<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>模块列表</title>
<script src="../../js/jquery-3.1.1.min.js" charset="utf-8" ></script>
<script src="../../js/Verification.js"></script>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="../../layui/css/layui.css" media="all">
<!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
<link rel="stylesheet" href="../../layui/css/treeselect.css">
</head>
<style>
#typeName{
    padding: 5px 0;
    min-width: 100%;
    border: 1px solid #d2d2d2;
    max-height: 300px;
    overflow-y: auto;
    background-color: #fff;
    border-radius: 2px;
    box-shadow: 0 2px 4px rgba(0,0,0,.12);
    box-sizing: border-box;
}
</style>
<body>
	<div class="demoTable">
		模块名字：
		<div class="layui-inline">
			<input class="layui-input" name="modName" id="modname"
				autocomplete="off" size="34">
		</div>
		
		<button class="layui-btn" data-type="reload">搜索</button>
		<button class="layui-btn layui-btn-primary" onclick="showAddOrUpdate('');">增加</button>
	</div>
	<table class="layui-table"
		lay-data="{ url:'../../drugModule/findAll.action', page:true, id:'idTest'}"
		lay-filter="demo">
		<thead>
			<tr>
				<th lay-data="{field:'modulePName', width:120, align:'center'}">上级模块</th>
				<th lay-data="{field:'modName', width:130, align:'center'}">模块名称</th>
				<th lay-data="{field:'url', width:310, align:'left'}">模块URL</th>
				<th lay-data="{field:'modDesc', width:220, align:'center'}">模块说明</th>
				<th lay-data="{fixed: 'right', width:178, align:'center', toolbar: '#barDemo'}">操作</th>
			</tr>
		</thead>
	</table>

	<script type="text/html" id="barDemo">
		<a class="layui-btn  layui-btn-xs" lay-event="edit">修改</a>
		<a class="layui-btn  layui-btn-danger layui-btn-xs" lay-event="del">删除</a>

</script>
	<script src="../../layui/layui.js" charset="utf-8"></script>
	

	<script>
	
		layui.use('table', function() {
			var table = layui.table;
			//监听表格复选框选择
			table.on('checkbox(demo)', function(obj) {
				console.log(obj)
			});
			//监听工具条
			table.on('tool(demo)', function(obj) {
	
				
				var data = obj.data;
				if (obj.event === 'del') {
					layer.confirm('真的删除么', function(index) {
						layer.close(index);
						var id = data.id;
						var url = "../../drugModule/delete.action";
						var datas = {
							'modId' : id
						};
						$.ajax({
							asyn : true,
							type : "POST",
							url : url,
							data : datas,
							success : function(msg) {
								if (msg.state == 0) {
									layer.msg(msg.msg);
									table.reload('idTest');
								} else {
									layer.msg(msg.msg, {
										  icon: 1,
										  time: 1000 //1秒关闭（如果不配置，默认是3秒）
										}, function(){
										  table.reload('idTest');
									});
								}
							},
							error : function(fh) {
								layer.msg(msg.msg);
							}
						},"json");
					});
				} else if (obj.event === 'edit') {
					showAddOrUpdate(data);
				}
				
			});
		
			var $ = layui.$, active = {
				reload : function() {
					//执行重载
					table.reload('idTest', {
						
						where : {
							'modName' : $("#modname").val()
						},
						page : {
							curr : 1
						}
					});
				}
			};
			
			$('.demoTable .layui-btn').on('click', function() {
				var type = $(this).data('type');
				active[type] ? active[type].call(this) : '';
			});
			
		});
		var num;
		function showAddOrUpdate(obj){
			var from = $("#fromStr").html();
			var addCen = layer.open({
		        type: 2//样式
		        ,skin: 'layui-layer-molv'//样式
		        ,area: ['85%', '86%']
		        ,title:"模块维护"//标题
		        ,id: 'mesFrom' //防止重复弹出
		        ,content: "moudelAddUpdate.html?modId="+obj.modId+"&ehyModId="+obj.ehyModId
		        ,shade: [0.8, '#393D49'] //显示遮罩
		        ,shadeClose:true//点击也能遮罩层关闭
		        ,anim:1//弹出动画 
		      });
			
		}
		
		layui.use('laydate', function(){
			  var laydate = layui.laydate;
			  //日期范围
			  laydate.render({
			    elem: '#test6'
			    ,range: true
			  });
		});

	  //鼠标放上去显示颜色
	  function showColor(){
	  	
		$("#tab tr:gt(0)").hover(
			function(){$(this).addClass("hover_bg")},
			function(){$(this).removeClass("hover_bg")}
		);
	  }
	  
	  
	  //删除一行
	  
	  function deleteRows(obj){
	  	
	  	var tr = obj.parentNode;
		var row = tr.rowIndex;
	  	$("#tab tr:eq("+row+")").remove();
	  }
	</script>

</body>
</html>